<template>
  <div style="margin-top:20px">
    <!-- ----------------------------------ge------------------------------------------->
    <el-table ref="multipleTable" height="520" border :data="rule_map" size='mini'>
      <template slot="empty">
        <el-empty :description="$t('暂无数据')"></el-empty>
      </template>
      <el-table-column prop="rule_id" align='center' :label="$t('规则ID')" width="80" />
      <el-table-column prop="proto" align='center' :label="$t('协议名称')" width="80">
        <template slot-scope="scope">
          {{ rule[scope.row.proto] }}
        </template>
      </el-table-column>
      <el-table-column prop="action" align='center' :label="$t('动作')" width="80">
        <template slot-scope="scope">
          {{ $t(actionList[scope.row.action]) }}
        </template>
      </el-table-column>
      <el-table-column prop="communication_type" align='center' :label="$t('报文类型')" width="80">
        <template slot-scope="scope">
          {{ $t(communicationTypeList[scope.row.communication_type]) }}
        </template>
      </el-table-column>
      <el-table-column prop="read_write_type" align='center' :label="$t('读写属性')" width="80">
        <template slot-scope="scope">
          {{ $t(readWriteTypeList[scope.row.read_write_type]) }}
        </template>
      </el-table-column>
      <el-table-column prop="register_type" align='center' :label="$t('寄存器类型')" width="160">
        <template slot-scope="scope">
          {{ $t(registerTypeList[scope.row.register_type]) }}
        </template>
      </el-table-column>
      <el-table-column prop="start_addr" align='center' :label="$t('起始地址')" />
      <el-table-column prop="stop_addr" align='center' :label="$t('结束地址')" />
      <el-table-column prop="accept_range" align='center' :label="$t('匹配范围')" width="100">
        <template slot-scope="scope">
          {{ $t(acceptRangeList[scope.row.accept_range]) }}
        </template>
      </el-table-column>
      <el-table-column align="center" :label="$t('操作')" width="160" fixed='right'>
        <template slot-scope="scope">
          <el-button type="success" plain @click="editRule(scope.row)" size='mini' :class="'edit' +(scope.$index+1)">{{$t('编辑')}}</el-button>
          <el-button type="danger" plain @click="deleteRule(scope.row)" size='mini' :class="'del' +(scope.$index+1)">{{$t('删除')}}</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import ruleArray from '../../ruleArray'
export default {
  name: 'GeTable',
  props: {
    ruleMap: {
      type: Array,
      default () {
        return []
      }
    }
  },
  watch: {
    ruleMap: {
      handler (newValue, oldValue) {
        this.rule_map = []
        newValue.forEach(val => {
          if (val.proto === 'ge') {
            this.rule_map.push(val)
          }
        })
      },
      deep: true // 深度监听
    }
  },
  data () {
    return {
      dialogVisible: false,
      ruleDialogVisible: false,
      rule_map: [],
      rule: ruleArray.rule,
      readWriteTypeList: ruleArray.readWriteTypeList,
      communicationTypeList: ruleArray.communicationTypeList,
      registerTypeList: ruleArray.registerTypeList,
      actionList: { 'accept': '允许', 'alert': '告警' },
      acceptRangeList: ruleArray.acceptRangeList
    }
  },
  mounted () {
    this.rule_map = []
    this.ruleMap.forEach(val => {
      if (val.proto === 'ge') {
        this.rule_map.push(val)
      }
    })
  },
  methods: {
    deleteRule (row) {
      this.$emit('delRuleMap', row)
    },
    editRule (row) {
      this.$emit('largeConfig', row)
    }
  }
}
</script>
